linux pipewire 蓝牙耳机无声
·
Table of Contents
解决方案
修改bluetooth策略
sudo vim /etc/bluetooth/main.conf
[Policy]
AutoEnable=true
JustWorksRepairing=always
AutoConnect=true
# end config
# 删除后重新配置
bluetoothctl devices
sudo cat /var/lib/bluetooth/88:D8:2E:2B:20:09/41:AA:00:56:F4:FC/info
bluetoothctl remove 41:AA:00:56:F4:FC
sudo systemctl restart bluetooth
常用配置与调试工具汇总
| 工具 | 用途 | 示例命令 |
|---|---|---|
| bluetoothctl | 蓝牙配对/连接底层控制 | info, connect, trust |
| pactl | PipeWire Pulse 兼容控制 | list sinks/cards, set-card-profile |
| pw-cli | PipeWire 原生节点检查 | list-objects, inspect |
| wireplumber 日志 | 策略/自动路由分析 | journalctl --user-unit=wireplumber -f |
| helvum (GUI) | PipeWire 节点连接可视化 | helvum(需安装) |
| qpwgraph (GUI) | 类似 helvum,Qt 版 | qpwgraph |
| btmon | 蓝牙 HCI 层抓包 | sudo btmon |
| dmesg -w | 内核蓝牙错误 | dmesg -w |
# 1. 检查蓝牙服务是否运行
systemctl --user status pipewire wireplumber
# 必须都是 active (running)
systemctl --user restart wireplumber pipewire pipewire-pulse
sudo systemctl restart bluetooth
# 2. 确认蓝牙硬件启用
rfkill list bluetooth
# 若 soft/hard blocked,执行:
# rfkill unblock bluetooth
# 3. 检查内核模块
lsmod | grep -E 'btusb|bluetooth|snd_bt_sco'
# 应有 bluetooth、btusb、可能还有 snd_bt_sco(用于 HFP)
# 使用 speaker-test 向默认蓝牙设备发送测试音
# 可能需要先用 `aplay -L` 查找具体设备名
speaker-test -D bluez:<设备名> -t wav -c 2
常用命令
wpctl status # 最常用。控制WirePlumber会话管理器,查看/切换默认设备,调节音量。
wpctl set-mute [ID] 0 # 取消静音
wpctl set-volume [ID] 0.5 # 设置音量为 50%
pw-cli info all # PipeWire的命令行接口,用于直接与服务器交互,进行低级操作。
pw-dump > dump.json # 将所有PipeWire对象(节点、设备等)的状态以JSON格式导出,用于详细分析或提交Bug报告
pw-top # 类似系统top命令,实时显示音频处理节点的性能数据(如延迟、X运行次数)
pw-play ./test.mp3 # 用于直接播放或录制音频文件,进行快速测试
pactl list cards
apt install helvum
helvum
蓝牙
bluetoothctl
> list # 查看适配器
> show # 当前适配器详情
> devices # 已知设备
> info <MAC> # 查看耳机详情:是否 Connected: yes, Trusted: yes
> connect <MAC> # 手动连接(有时 GUI 配对未真正连通音频)
# 实时监听 BlueZ D-Bus 消息(高级)
sudo busctl monitor org.bluez
# 或用 btmon(需 root)
sudo btmon
# 这里发现是配对认证失败: 密钥不匹配:你的耳机里可能保存了与这台电脑或其他设备配对的旧密钥: 或者系统升级后默认策略收紧
sudo cat /var/lib/bluetooth/11:11:2E:2B:20:09/22:22:00:56:F4:FC/info
# 这里保存了旧的协商密钥
# 删除耳机,重新配对后正常
bluetoothctl remove 41:AA:00:56:F4:FC
bluetoothctl
> scan on
pipewire 调试
# 列出所有 sink(输出设备)
pactl list sinks short
# 更详细(关键!看 active port 和 profile)
pactl list sinks
# 列出所有 PipeWire 节点(比 pactl 更底层)
pw-cli list-objects | grep -A5 -B5 -i bluetooth
# 查看蓝牙设备节点属性
pw-cli inspect <node-id> # 如 42
cp /usr/share/wireplumber/bluez-monitor.d/50-bluez-config.lua ~/.config/wireplumber/bluez-monitor.d/
cat > ~/.config/wireplumber/bluez-monitor.d/50-bluez-config.lua<<EOF
bluez_monitor.properties = {
["bluez5.auto-switch"] = true,
["bluez5.headset-voice"] = true, -- ← 若你不需要通话,可设为 false
}
EOF
systemctl --user restart wireplumber
# PipeWire 层
pactl get-sink-volume @DEFAULT_SINK@
pactl get-sink-mute @DEFAULT_SINK@
# ALSA 层(有时 PipeWire 未接管)
alsamixer -D pipewire
# 或
alsamixer # 按 F6 选蓝牙设备(若有)
sudo apt install helvum qpwgraph pavucontrol
# 用 pactl 指定 sink 播放测试音
pactl play-sample bell-window bluez_output.XX_XX_XX_XX_XX_XX.a2dp-sink
# 或用 pw-play(PipeWire 原生命令)
pw-play --target=bluez_output.XX_XX_XX_XX_XX_XX.a2dp-sink /usr/share/sounds/alsa/Front_Center.wav